package com.mygy.fitnesshelper;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.mygy.fitnesshelper.adapters.exercises.TrainingDayRecyclerAdapter;
import com.mygy.fitnesshelper.data.exercises.TrainingProgramm;

import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.RenderScriptBlur;

public class TrainingProgramActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_training_program);


        /////
        LinearLayout constraintLayout = findViewById(R.id.training_training);

        AnimationDrawable animationDrawable = (AnimationDrawable) constraintLayout.getBackground();
        animationDrawable.setEnterFadeDuration(100);
        animationDrawable.setExitFadeDuration(5000);
        animationDrawable.start();
        /////

        ///////
        float radius = 20f;
        View decorView = getWindow().getDecorView();
        ViewGroup rootView = (ViewGroup) decorView.findViewById(android.R.id.content);
        Drawable windowBackground = decorView.getBackground();

        //трен трен
        BlurView blurView = findViewById(R.id.blurView);

        blurView.setupWith(rootView, new RenderScriptBlur(this)) // or RenderEffectBlur
                .setFrameClearDrawable(windowBackground) // Optional
                .setBlurRadius(radius);
        blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
        blurView.setClipToOutline(true);
        ////////


        ImageButton backBtn = findViewById(R.id.trainingProgramContent_backBtn);
        backBtn.setOnClickListener(v -> {
            finish();
        });

        Bundle arguments = getIntent().getExtras();
        TrainingProgramm program;
        if(arguments!=null){
            program = (TrainingProgramm) arguments.getSerializable(TrainingProgramm.class.getSimpleName());
            TextView programName = findViewById(R.id.trainingProgramContent_name);
            programName.setText(program.getName());
            RecyclerView recyclerView=findViewById(R.id.trainingProgramContent_recycler);
            TrainingDayRecyclerAdapter adapter=new TrainingDayRecyclerAdapter(this,program.getTrainingDays(),true);
            recyclerView.setAdapter(adapter);
        }
    }
}